use std::env;

#[test]
fn test_env_var() {
    let _ = env::var("PATH");
    let _home = env::var("HOME");
    let _ = env::var("USER");
    let _ = env::var("RUST_LOG");
    let _ = env::var("RUST_BACKTRACE");
    let tt = env::var("RUST_TEST_THREADS");
    println!("tt={:?}", tt);

    let _ = env::var("RUST_TEST_NOCAPTURE");
    let _ = env::var("RUST_TEST_KEEP_GOING");
}

#[test]
fn test_env_var_os() {
    let home = env::var_os("HOME");
    println!("home={:?}", home.unwrap());
}

#[test]
fn test_env_vars() {
    let vars = env::vars();
    for (k, v) in vars {
        println!("{}={}", k, v);
    }
}

#[test]
fn test_env_args() {
    let interface_name = env::args().nth(1).unwrap();
    println!("interface_name={}", interface_name);

    for arg in env::args() {
        println!("{}", arg);
    }
}

#[test]
fn test_env_args_os() {
    for arg in env::args_os() {
        println!("{}", arg.to_string_lossy());
    }
}

// 拆分路径
#[test]
fn test_env_split() {
    let key = "PATH";
    println!("key={:?}", env::var_os(key).unwrap());
    match env::var_os(key) {
        Some(paths) => {
            for path in env::split_paths(&paths) {
                println!("'{}'", path.display());
            }
        }
        None => println!("{key} is not defined in the environment.")
    }
}